package net.yla.smartbus.core.util;

import java.util.Date;

/**
 * @Author : 默苍离
 * @Create_Date : 2020/08/12/08:52
 * @Pack_name : org.jgs1904 : Milliseconds
 * *****************************************************
 * 注释:返回友好的持续时间描述字符串。
 */

public class GetDuration {

    public static final long S = 1000;
    public static final long M = S * 60;
    public static final long H = M * 60;
    public static final long D = H * 24;


    public static String getDuration(int milliseconds) {

        Date now = new Date();
        long time = now.getTime() - milliseconds;

        String string = "";
        long d = time / D % 24;
        long h = time / H % 60;
        long m = time / M % 60;
        long s = time / S % 60;

        if (d == 0) {
            string = "跨小时为（未跨天）：" + h + "：小时  " + m + "：分  " + s + "：秒  ";
        } else if (h == 0) {
            string = "跨分（未跨时）：" + m + "：分  " + s + "：秒  ";
        } else if (m == 0) {
            string = "不满一分钟:" + s + "：秒  ";
        } else if (s == 0) {
            string = "无时间跨度：" + 0 + "：秒  ";
        } else {
            string = d + "：天  " + h + "：小时  " + m + "：分  " + s + "：秒  ";
        }

        return string;

    }
}
